/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.rs.controller;

//import com.xy.biz.dd.domain.req.SaveDataCellRequest;
//import com.xy.biz.dd.domain.req.SaveDataTableRequest;
//import com.xy.biz.dd.domain.resp.GetDataTemplateResponse;
import com.xy.biz.rs.client.ManufactureRecordTemplateClient;
import com.xy.biz.rs.domain.converter.ManufactureRecordTemplateConverter;
import com.xy.biz.rs.domain.query.ManufactureRecordTemplateQuery;
import com.xy.biz.rs.domain.req.*;
import com.xy.biz.rs.domain.resp.GetManufactureRecordTemplateResponse;
import com.xy.biz.rs.service.ManufactureRecordTemplateService;
import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

/**
 *
 *
 * @author zsp
 * @date 2021-4-13
 */
@Api(tags = "生产记录模板")
@Slf4j
@RestController
@RequestMapping("/api/rs/manufacture/record_template")
public class ManufactureRecordTemplateController implements ManufactureRecordTemplateClient {

	@Autowired
	private ManufactureRecordTemplateService manufactureRecordTemplateService;

	@ApiOperation("保存生产记录模板")
	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save")
	public Result<?> saveManufactureRecordTemplate(@RequestBody SaveManufactureRecordTemplateRequest request) {
		return manufactureRecordTemplateService.saveManufactureRecordTemplate(ManufactureRecordTemplateConverter.toBO(request));
	}

	@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update")
	public Result<?> updateManufactureRecordTemplate(@RequestBody SaveManufactureRecordTemplateRequest request) {
		return manufactureRecordTemplateService.updateManufactureRecordTemplate(request);
	}

	@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update_status")
	public Result<?> updateManufactureRecordTemplateStatus(@RequestBody UpdateManufactureRecordTemplateRequestStatus request) {
		return manufactureRecordTemplateService.updateManufactureRecordTemplateStatus(request);
	}

	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteManufactureRecordTemplate(@RequestBody GetManufactureRecordTemplateRequest request) {
		manufactureRecordTemplateService.deleteManufactureRecordTemplate(request.getManufactureRecordTemplateId());
		return Result.success();
	}

	@Validatable
	@PostMapping(value = "/get")
	@Override
	public Result<GetManufactureRecordTemplateResponse> getManufactureRecordTemplate(@RequestBody GetManufactureRecordTemplateRequest request) {
		return null;//manufactureRecordTemplateService.getManufactureRecordTemplate(request.getManufactureRecordTemplateId());
	}

	@PostMapping(value = "/list_by_ids")
	@Override
	public Result<List<GetManufactureRecordTemplateResponse>> listManufactureRecordTemplateById(@RequestBody Collection<Long> collection) {
		return Result.success(ManufactureRecordTemplateConverter.toResponse(manufactureRecordTemplateService.listManufactureRecordTemplateById(collection)));
	}

	@PostMapping(value = "/list")
	@Override
	public Result<List<GetManufactureRecordTemplateResponse>> listManufactureRecordTemplate(@RequestBody ListManufactureRecordTemplateRequest request) {
		return Result.success(ManufactureRecordTemplateConverter.toResponse(manufactureRecordTemplateService.listManufactureRecordTemplate(ManufactureRecordTemplateConverter.toQuery(request))));
	}

	@PostMapping(value = "/count")
	@Override
	public Result<Integer> countManufactureRecordTemplate(@RequestBody ListManufactureRecordTemplateRequest request) {
		return Result.success(manufactureRecordTemplateService.countManufactureRecordTemplate(ManufactureRecordTemplateConverter.toQuery(request)));
	}

	@PostMapping(value = "/page")
	@Override
	public Result<Page<GetManufactureRecordTemplateResponse>> pageManufactureRecordTemplate(@RequestBody ListManufactureRecordTemplateRequest request) {
		ManufactureRecordTemplateQuery query = ManufactureRecordTemplateConverter.toQuery(request);
		List<GetManufactureRecordTemplateResponse> list = ManufactureRecordTemplateConverter.toResponse(manufactureRecordTemplateService.listManufactureRecordTemplate(query));
		int count = manufactureRecordTemplateService.countManufactureRecordTemplate(query);
		return Result.success(new Page<>(list, count));
	}


//	@ApiOperation("保存数据表,同时响应模板信息")
//	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/save_data_table")
//	public Result<GetDataTemplateResponse> saveDataTable(@RequestBody SaveDataTableRequest request) {
//		return null;//manufactureRecordTemplateService.saveDataTable(request);
//	}


//	@ApiOperation("修改数据表,同时响应模板信息")
//	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/update_data_table")
//	public Result<GetDataTemplateResponse> updateDataTable(@RequestBody SaveDataTableRequest request) {
//		return null;//manufactureRecordTemplateService.updateDataTable(request);
//	}


//	@ApiOperation("保存单元格数据,同时响应模板信息")
//	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/save_data_cell")
//	public Result<GetDataTemplateResponse> saveDataCell(@RequestBody SaveDataCellRequest request) {
//		return null;//manufactureRecordTemplateService.saveDataCell(request);
//	}


//	@ApiOperation("修改单元格数据,同时响应模板信息")
//	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/update_data_cell")
//	public Result<GetDataTemplateResponse> updateDataCell(@RequestBody SaveDataCellRequest request) {
//		return null;//manufactureRecordTemplateService.updateDataCell(request);
//	}

	@PostMapping(value = "/get_record_template_by_dict_code")
	public Result<GetManufactureRecordTemplateResponse> getRecordTemplateByDictCode(@RequestBody GetByProductDictCodeRequest request) {
		return manufactureRecordTemplateService.getRecordTemplateByDictCode(request);
	}

}
